package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entry.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user where username = #{username}")
    User selectByUsername(String username);

    @Select("select * from user")
    @Results(
            {
                    @Result(column = "id",property = "id"),
                    @Result(column = "username",property = "username"),
                    @Result(column = "keepalive",property = "keepalive"),
                    @Result(column = "password",property = "password"),
                    @Result(column = "cleanstate",property = "cleanstate"),
                    @Result(column = "clientid",property = "clientid"),
                    @Result(column = "username",property = "messages",javaType = List.class,
                            many = @Many(select = "com.example.demo.mapper.MessageMapper.selectByUsername"))
            }
    )
    List<User> selectAllUserAndMessages();
    @Select("select * from user where username = #{username}")
    @Results(
            {
                    @Result(column = "id",property = "id"),
                    @Result(column = "username",property = "username"),
                    @Result(column = "keepalive",property = "keepalive"),
                    @Result(column = "password",property = "password"),
                    @Result(column = "cleanstate",property = "cleanstate"),
                    @Result(column = "clientid",property = "clientid"),
                    @Result(column = "username",property = "messages",javaType = List.class,
                            many = @Many(select = "com.example.demo.mapper.MessageMapper.selectByUsername"))
            }
    )
    List<User> selectOneUserAndMessages(String username);
}
